<!--
 * @Author: 卢金辉 3400170271@qq.com
 * @Date: 2025-09-11 08:46:33
 * @LastEditors: 肖世渊 xiao2655308229@163.com
 * @LastEditTime: 2025-09-17 20:27:16
 * @FilePath: \23级信算卢金辉\city\src\pages\components\Bottom2.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
        <div ref="bottom2" style="height: 150px;margin-top: 20px;"></div>
    </div>
</template>
<script>
import { Bar } from '@antv/g2plot';
import { get } from '@/utils/request';

import { mapState } from 'vuex';

export default {
    data() {
        return {
            title: '监测月报',
            params: {
            },
            MonthData: [],
            // 创建一个图表实例
            line: null,
        }
    },
    computed: {
        ...mapState(['ed']),
    },
    // 侦听器
    watch:{
        ed:{
            handler(n,o){
                // 根据设备信息重新查询数据 渲染图表
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getMonthData();
                // 根据最新获取的数据重新渲染图表
                this.column.changeData(this.MonthData);
            },
            // 深度侦听
            deep:true,
        }
    },
    methods: {
        loadLine() {
            this.column = new Bar(this.$refs.bottom2, {
                data:this.MonthData,
                yField: 'type',
                xField: 'value',
                xAxis: {
                    label: {
                        style: {
                            fill: "white",
                            fontSize: 13,
                        },
                    }
                },
                yAxis: {
                    label: {
                        autoRotate: false,
                        style: {
                            fill: "white",
                            fontSize: 13,
                        },
                    },
                },
                scrollbar: {
                    type: 'vertical',
                    // 滚动条样式配置
                    style: {
                        trackColor: 'black',
                        thumbColor: 'white',
                    },
                },
                tooltip: {
                    domStyles: {
                        "g2-tooltip": {
                            background: "#147",
                            color: "white",
                            fontSize: 20,
                        },
                    },
                },
            });

            this.column.render();
        },
        async getMonthData() {
            let res = await get('/dashboard/queryMouthData', this.params);
            console.log(res,"获取响应");
            this.MonthData = res.data;
        }
    },

    async mounted() {
        await this.getMonthData();
        this.loadLine();
    },
}
</script>
<style lang="less" scoped></style>